// Child32.jsx 组件之间传值-子组件
import { Component } from 'react'
import '../assets/css/Child.css'
import event from '../utils/bus'

export default class Child31 extends Component {
  state = {
    fromData: '等待接收数据'
  }

  componentDidMount () {
    // 生命周期钩子，当前组件挂载完成后监听事件
    event.on('my-event', val => {
      this.setState({
        fromData: val
      })
    })
  }

  render () {
    return (
      <div className='child-container'>
        <h3>子组件02</h3>
        <p>接收数据：{this.state.fromData}</p>
      </div>
    )
  }
}
